home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / SOURCE / DACDIR.C < prev    next >
C/C++ Source or Header  |  1992-04-05  |  1KB  |  71 lines

  1. /* Output to SB DAC in single sample mode */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include <conio.h>
  6. #include <io.h>
  7. #include <alloc.h>
  8. #include <dos.h>
  9.  
  10. #include "sb.h"
  11.  
  12. /* Read first 64000 bytes of a raw sample file and play the sample */
  13. void main(int argc, char *argv[])
  14. {
  15.     FILE *f;
  16.     signed char *raw;
  17.     unsigned sample_len;
  18.     register int j, i;
  19.     int tmp;
  20.  
  21.     if(argc != 2)
  22.     {
  23.     puts("Usage: dacdir sample_file");
  24.     exit(1);
  25.     }
  26.  
  27.     if(Sb_Get_Params())
  28.     {
  29.         puts("BLASTER environment variable not set.");
  30.         exit(1);
  31.     }
  32.  
  33.     if(Sb_Init())
  34.     {
  35.     printf("Could not find Soundblaster!\n");
  36.     exit(1);
  37.     }
  38.     printf("Found Soundblaster at %xh.\n",SbIOaddr);
  39.  
  40.     f = fopen(argv[1],"rb");
  41.     if(f == NULL)
  42.     {
  43.     printf("Could not open sample file %s\n",argv[1]);
  44.     }
  45.     sample_len = (unsigned)filelength(fileno(f));
  46.  
  47.     raw = (signed char *)malloc(sample_len);
  48.     fread(raw,1,sample_len,f);
  49.  
  50.     fclose(f);
  51.  
  52.     Sb_Voice(1);
  53.  
  54.     for(i = 0; i < sample_len; i++)
  55.     {
  56.         writedac(0x10);
  57.         writedac(raw[i]);
  58.  
  59.         while(inportb(SbIOaddr+DSP_DATA_AVAIL) & 0x80)
  60.         ;
  61.     }
  62.  
  63.     Sb_Voice(0);
  64.  
  65.     free(raw);
  66.  
  67.     Sb_Init();
  68.  
  69.     exit(0);
  70. }
  71.